<template>
  <div class="ware">
    <nav-bar class="navBar">
      <router-link to="/" slot="left">
        <div class="left"></div>
      </router-link>
      <div class="center" slot="center">
        <ul>
          <li v-for="name in sorts" :key="name">
            {{ name }}
          </li>
        </ul>
      </div>
      <div class="right" slot="right">
        <img src="../assets/more.png" />
      </div>
    </nav-bar>
    <div
      class="main"
      v-for="(item, index) in ware"
      :key="index"
      v-show="currentIndex == index"
    >
      <div class="img">
        <img :src="item.img" />
      </div>
    </div>
    <div class="foot"></div>
  </div>
</template>

<script>
import navBar from "../components/navBar.vue";
export default {
  data() {
    return {
      sorts: ["商品", "详情", "评价", "推荐"],
      ware: "",
      currentIndex: 0,
    };
  },
  components: {
    navBar,
  },
  methods: {
    mounted() {
      this.$bus.$on("getIndex", (index) => {
        this.currentIndex = index;
      });
      this.$bus.$on("getWare", (ware) => {
        this.ware = ware;
      });
    },
    beforeDestroy() {
      this.$bus.$off("getIndex");
      this.$bus.$off("getWare");
    },
  },
};
</script>

<style scoped>
.ware .navBar {
  position: fixed;
  top: 0px;
  height: 50px;
  width: 320px;
  border-bottom: 2px solid rgb(246, 246, 246);
  display: flex;
  flex-flow: row;
}
.ware .navBar .left {
  width: 10px;
  height: 10px;
  transform: rotate(-45deg);
  border: none;
  border-left: solid 3px rgb(93, 95, 106);
  border-top: solid 3px rgb(93, 95, 106);
  position: relative;
  margin-top: 20px;
  margin-left: 20px;
}
.ware .navBar .center {
  margin-left: 35px;
}
.ware .navBar .center ul {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: space-evenly;
}
.ware .navBar .center li {
  width: 45px;
  display: inline-flex;
  list-style: none;
  justify-content: center;
  align-items: center;
}
.ware .navBar .right {
  margin-left: 25px;
  margin-top: 10px;
}
.ware .navBar .right img {
  width: 30px;
}
.ware .foot {
  height: 50px;
  width: 320px;
  position: fixed;
  bottom: 0px;
  z-index: 100;
  background: white;
}
</style>